#include <pwd.h>
#include <signal.h>
#include "header.h"

static void my_alarm(int);

int
main(void){
    struct passwd *ptr;

    ptr = getpwnam("green");
    printf("%s\n",ptr->pw_name);
    
    signal(SIGALRM, my_alarm);
    alarm(1);

    for(;;){
        if((ptr = getpwnam("green")) == NULL)
            err_sys("getpwnam error");
        if(strcmp(ptr->pw_name,"green") != 0)
            printf("return value corrupted!, pw_name = %s\n", ptr->pw_name);
    }
}

static void
my_alarm(int signo){
    struct passwd *rootptr;

    printf("in signal handler\n");
    rootptr = getpwnam("green"); /* hang up */
    printf("here");
    if((rootptr = getpwnam("root")) == NULL)
        printf("error\n");
        err_sys("getpwnam(root) error");
    alarm(1);
    return;
}
